<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php echo DESCRIPTION; ?>
<?php echo KEYWORD; ?>
<title><?php echo WEB_TITLE;?></title>
<link href="<?php echo  WEB_URL;?>/styles/style.css" rel="stylesheet" />
<link href="<?php echo  WEB_URL;?>/styles/ads.css" rel="stylesheet" />
<link type="text/css" href="<?php echo  WEB_URL;?>/styles/ui-lightness/jquery-ui-1.8rc2.custom.css" rel="stylesheet" />

<!-- StyleSheet Plugin-->
<link type="text/css" href="<?php echo  WEB_URL;?>/styles/jqtransform.css" rel="stylesheet" />
<link type="text/css" href="<?php echo  WEB_URL;?>/styles/jquery.checkbox.css" rel="stylesheet" />
<link type="text/css" href="<?php echo  WEB_URL;?>/styles/vtip.css" rel="stylesheet" />
<link rel="stylesheet" href="<?php echo  WEB_URL;?>/styles/validationEngine.jquery.css" type="text/css" media="screen"/>

<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/jquery-ui-1.8rc2.custom.min.js"></script>

<!-- Script Plugin -->
<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/jquery.jqtransform.js"></script>
<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/jquery.checkbox.min.js"></script>
<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/vtip.js"></script>
<script src="<?php echo  WEB_URL;?>/scripts/jquery/jquery.validationEngine.js" type="text/javascript"></script>
<script src="<?php echo  WEB_URL;?>/scripts/jquery/jquery.validationEngine-th.js" type="text/javascript"></script>
<script type="text/javascript" src="<?php echo  WEB_URL;?>/scripts/jquery/tab.js"></script>

<script type="text/javascript">
$(function(){
	
	$('form').jqTransform({imgPath:'<?php echo  WEB_URL;?>/styles/images/jqtransform/'});

	$('#edit_info_form').validationEngine();
	$('#edit_password_form').validationEngine();
	$('#edit_password_form input').attr('style','width: 150px;');
	
	var field = {};
	$('#edit_info_form').delegate('input','change', function(){
		field[$(this).attr('id')] = $(this).val();
	});

	var has_change = false;
	$('#edit_info_form').submit(function(){
		var uname = $('#uid').val();

		$('#edit_info_form input').change(function(){ has_change = true; });

		if(has_change){
			$.ajax({
				type: "POST",
				url: "../query.php",
				data: {editprofile:true, username:uname, change_data:field},
				dataType: 'json',
				beforeSend: function(x){$('#edit_info_form #loading').html('<img src="../styles/images/loading.gif"/>');},
				success: function(msg){	
					$('#edit_info_form #loading').html('แก้ไข้ข้อมูลเรียบร้อยแล้วค่ะ');
				}			   
			});
		}else{
			alert('ไม่สามารถอัพเดทได้เพราะไม่มีข้อมูลใดเปลี่ยนแปลง');
		}
		return false;	
	});	

	$('#edit_password_form').submit(function(){
		var oldpwd = $('#old_pass').val();
		var newpwd = $('#password').val();
		var username = $('#uid').val();
		var check_error = $('div').hasClass('formError');
		
		$('#edit_password_form #loading').html('');  // set invisible
		
		if(!check_error){
			$.ajax({
				type: "POST",
				url: "../query.php",
				data: {changepwd:true, opwd:oldpwd, newpass:newpwd, uname:username},
				dataType: 'json',
				beforeSend: function(x){$('#edit_password_form #loading').html('<img src="../styles/images/loading.gif"/>');},
				success: function(msg){
					alert(msg.status);
					if(msg.status){
						$('#edit_password_form #loading').html('รหัสผ่านถูกแก้ไขเรียบร้อยแล้วค่ะ');
					}else{
						alert('กรุณากรอกรหัสผ่านเดิมให้ถูกต้องด้วยนะค่ะ');
						$('#edit_password_form #loading').html('');
					}
				}			   
			});
		}
		
		return false;
		
	});


	
});
</script>

</head>

<body>
	<div class="page">
    
    	<?php require_once('../header.php');?>
        
        <div class="content">
        	<div id="wrap_top">
            	<div id="wrap_top_left">
                	<!--<div id="wrap_ads">                	 
                        <div id="wrap_728x90"></div>
                	</div>-->
   
                    <div class="tabs">
                          <a tab="#tab_edit_profile">แก้ไขข้อมูลส่วนตัว</a>        
                          <a tab="#tab_edit_password">แก้ไขรหัสผ่าน</a>        
                    </div>
            
                    <div id="tab_edit_profile" class="tab_page">
                    <?php
                    	$get_member_sql = $db->select_query("SELECT * FROM members WHERE username = '".$_SESSION['usr']."'");
						$get_member_rs = $db->fetch($get_member_sql);
					?>
					<input type="hidden" name="uid" id="uid" value="<?php echo $get_member_rs['username']?> " />
                    	<form id="edit_info_form" action="#" method="post" enctype="multipart/form-data" >
                            <table width="740" border="0" cellspacing="2" cellpadding="5">
                              <tr>
                                <td colspan="5">
                                	<div id="title"><h1>ข้อมูลทั่วไป</h1> <h3>เพื่อเพิ่มความน่าเชือถือให้กับตัวผู้ลงประกาศ และสร้างความมั่นใจให้กับผู้ที่เข้ามาดู กรุณาลงข้อมูลให้ครบด้วยนะค่ะ</h3></div>
                  					<div class="clear" style="margin-top:-5px;"></div>
                                </td>
                              </tr>
                              <tr>
                                <td><div align="right"><strong>ชื่อ :</strong></div></td>
                                <td>
                                	<label for="fname"></label>
                                	<input type="text" name="fname" id="fname" <?php !empty($get_member_rs['fname'])? print 'value="'.$get_member_rs['fname'].'"' : print ''; ?>/>
                                </td>
                                <td><div align="right"><strong>นามสกุล :</strong></div></td>
                                <td colspan="2">
                                	<label for="lname"></label>
                                	<input type="text" name="lname" id="lname" <?php !empty($get_member_rs['lname'])? print 'value="'.$get_member_rs['lname'].'"' : print ''; ?>/>
                                </td>
                              </tr>
                              <tr>
                                <td><div align="right"><strong>ชื่อแทนตัว :</strong></div></td>
                                <td>
                                	<label for="card_id"></label>
                                	<input type="text" name="poster_name" id="poster_name" title="ชื่อที่ใช้แสดงให้คนทั่วไปเห็น" class="vtip validate[required]" <?php !empty($get_member_rs['poster_name'])? print 'value="'.$get_member_rs['poster_name'].'"' : print ''; ?> /></td>
                                <td><div align="right"><strong>เพศ :</strong></div></td>
                                <td width="95">
                                	<input name="sex" type="radio" id="sex" value="m" <?php ($get_member_rs['sex'] == 'm')? print 'checked="checked"' : print ''; ?> />
                                	<label for="m"> ชาย</label>
                               	</td>
                                <td width="100">
                                	<input type="radio" name="sex" id="sex" value="f" <?php ($get_member_rs['sex'] != 'm')? print 'checked="checked"' : print ''; ?> />
                                	<label for="f"> หญิง</label>
                              	</td>
                              </tr>
                              <tr>
                                <td><div align="right"><strong>อีเมล :</strong></div></td>
                                <td>
                                	<label for="email"></label>
                                	<input type="text" name="email" id="email"  title="กรุณากรอกอีเมลที่ใช้งานได้จริงเพราะระบบจะส่งลิ้งค์สำหรับยืนยันตัวตนไปที่อีเมลนี้" class="vtip validate[required,custom[email]]" <?php !empty($get_member_rs['email'])? print 'value="'.$get_member_rs['email'].'" ' : print ''; ?> />
                               	</td>
                                <td>&nbsp;</td>
                                <td colspan="2">&nbsp;</td>
                              </tr>
                              <!--<tr>
                                <td><div align="right"><strong>รูปที่ใช้แสดง :</strong></div></td>
                                <td>&nbsp;</td>
                                <td colspan="3"><div align="right"></div></td>
                              </tr>-->
                              <tr>
                                <td><div align="right"><strong>ที่อยู่ :</strong></div></td>
                                <td>
                                	<label for="add_no"></label>
                                	<input type="text" name="add_no" id="add_no" <?php !empty($get_member_rs['address'])? print 'value="'.$get_member_rs['address'].'"' : print ''; ?>/><div align="right"></div>
                              	</td>
                                <td><div align="right"><strong>ตำบล :</strong></div></td>
                                <td colspan="2">
                                	<label for="add_no"></label>
                                	<input type="text" name="tumbon" id="tumbon" <?php !empty($get_member_rs['tumbon'])? print 'value="'.$get_member_rs['tumbon'].'"' : print ''; ?>/>
                              	</td>
                              </tr>
                              <tr>
                                <td><div align="right"><strong>อำเภอ :</strong></div></td>
                                <td>
                                	<label for="tumbon"></label>
                                	<input type="text" name="amphur" id="amphur" <?php !empty($get_member_rs['amphur'])? print 'value="'.$get_member_rs['amphur'].'"' : print ''; ?>/>
                                	</td>
                                <td><div align="right"><strong>จังหวัด :</strong></div></td>
                                <td colspan="2">
                                	<label for="amphur"></label>
                                	<input type="text" name="province" id="province" <?php !empty($get_member_rs['province'])? print 'value="'.$get_member_rs['province'].'"' : print ''; ?>/>
                               	</td>
                              </tr>
                              <tr>
                                <td><div align="right"><strong>ไปรษณีย์ :</strong></div></td>
                                <td>
                                	<label for="province"></label>
                                	<input type="text" name="postcode" id="postcode" <?php !empty($get_member_rs['postcode'])? print 'value="'.$get_member_rs['postcode'].'"' : print ''; ?>/>
                              	</td>
                                <td><div align="right"><strong>เบอร์แฟ็กซ์ :</strong></div></td>
                                <td colspan="2">
                                	<label for="postcode"></label>
                                    <input type="text" name="fax" id="fax" <?php !empty($get_member_rs['fax'])? print 'value="'.$get_member_rs['fax'].'"' : print ''; ?>/>
                               	</td>
                              </tr>
                              <tr>
                                <td><div align="right"><strong>โทรศัพท์มือถือ :</strong></div></td>
                                <td>
                                	<label for="mobile_phone"></label>
                                	<input type="text" name="mobile_phone" id="mobile_phone" <?php !empty($get_member_rs['mobile_no'])? print 'value="'.$get_member_rs['mobile_no'].'"' : print ''; ?>/>
                               	</td>
                                <td><div align="right"><strong>โทรศัพท์บ้าน :</strong></div></td>
                                <td colspan="2">
                                	<label for="phone"></label>
                                	<input type="text" name="phone" id="phone" <?php !empty($get_member_rs['phone'])? print 'value="'.$get_member_rs['phone'].'"' : print ''; ?>/>
                              	</td>
                              </tr>
                              <tr>
                                <td>&nbsp;</td>
                                <td>
                                	<input type="submit" name="submit" id="submit" value="อัพเดทข้อมูล" />
                                	<input type="reset" name="reset" id="reset" value="กรอกข้อมูลใหม่" />
                               	</td>
                                <td colspan="3"><span id="loading"></span></td>
                              </tr>
                            </table>                    
                    	</form> 
                    </div>
                    
                    <div id="tab_edit_password" class="tab_page">
                    	<form id="edit_password_form" action="#" method="post" enctype="multipart/form-data" >
                        <table width="740" border="0" cellspacing="2" cellpadding="5">
                              <tr>
                                <td colspan="5">
                                	<div id="title"><h1>ข้อมูลสำหรับเข้าสู่ระบบ</h1></div>
                  					<div class="clear" style="margin-top:-5px;"></div>
                                </td>
                              </tr>
                              <tr>
                                <td width="175"><div align="right"><strong>ชื่อผู้ใช้งาน :</strong></div></td>
                                <td width="200">
                                	<label for="username"></label>
                                	<input type="text" name="username" id="username" title="กรูณากรอกชื่อผู้ใช้งานเป็นภาษาอังกฤษเท่านั้น และต้องมากกว่า 4 ตัวอักษร" class="vtip validate[required,custom[noSpecialCaracters],length[4,20],ajax[ajaxUser]]" <?php !empty($get_member_rs['username'])? print 'value="'.$get_member_rs['username'].'" disabled="disabled"' : print ''; ?> />
                                </td>
                                <td width="116"><div align="right"><strong>รหัสผ่านเดิม :</strong></div></td>
                                <td colspan="2">
                                	<label for="old_pass"></label>
                                	<input type="password" name="old_pass" id="old_pass" title="กรอกรหัสผ่านเดิม" class="vtip validate[required,length[4,32]]" /></td>
                              </tr>
                              <tr>
                                <td><div align="right"><strong>รหัสผ่านใหม่ :</strong></div></td>
                                <td>
                                	<label for="password"></label>
                                	<input type="password" name="password" id="password" title="รหัสผ่านใหม่ต้องมีอย่างน้อย 4 ตัวอักษร" class="vtip validate[required,length[4,32]]" />
                               	</td>
                                <td><div align="right"><strong>ยีนยันรหัสผ่านใหม่ :</strong></div></td>
                                <td colspan="2">
                                	<label for="confirm_pass"></label>
                                	<input type="password" name="confirm_pass" id="confirm_pass" title="ยืนยันรหัสผ่านจะต้องตรงกันกับรหัสผ่านใหม่ที่ตั้ง" class="vtip validate[required,confirm[password]]" />
                              	</td>
                              </tr>
                              <tr>
                              	<td></td>
                              	<td>
                              		<div align="left">
                              			<input type="submit" name="update_password" value="อัพเดทข้อมูล" />
                              			<input type="reset" name="reset_password" value="กรอกข้อมูลใหม่" />
                              		</div>
                              	</td>
                              	<td colspan="3"><span id="loading"></span></td>
                              </tr>
                        	</table>  
                    	</form> 
                    </div>
                    <script type="text/javascript">
                    <!--
                    $.tabs('.tabs a'); 
                    //-->
                    </script>
                                    
                                                                
              	</div>
              	
              	<?php require('user_menu.php');?>
                
            </div>
            
            
        </div>
        
        <?php require_once('../footer.php');?>
        
    </div>
</body>
</html>